package com.amayadream.webchat.serviceImpl;

import java.util.List;
import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.amayadream.webchat.pojo.ChatRecord;
import com.amayadream.webchat.dao.IChatRecordDao;
import com.amayadream.webchat.service.IChatRecordService;
import com.amayadream.webchat.service.ILogService;

@Service(value = "chatrecordService")
public class ChatServicelmpl implements IChatRecordService{

	 @Resource private IChatRecordDao chatrecordDao;
	 @Resource private ChatRecord chatrecord;
	public List<ChatRecord> selectByFromid(String fromid,int page,int pageSize){
		int start = 1;
        int end = pageSize;
        if(page != 1) {
            start = pageSize * (page - 1) + 1;
            end = pageSize * page;
        }
        return chatrecordDao.selectByFromid(fromid, start, end);
	}
    public List<ChatRecord> selectByToid(String toid,int page, int pageSize){
    	int start = 1;
        int end = pageSize;
        if(page != 1) {
            start = pageSize * (page - 1) + 1;
            end = pageSize * page;
        }
        return chatrecordDao.selectByToid(toid, start, end);
    }
    public boolean insert(ChatRecord chatrecord){
    	return chatrecordDao.insert(chatrecord);
    	
    }
    public int selectCountByFromid(String fromid,int pageSize){
    	int pageCount = Integer.parseInt(chatrecordDao.selectCountByFromid(fromid).getFromid());
        return pageCount % pageSize == 0 ? pageCount/pageSize : pageCount/pageSize + 1;
    }
    public int selectCountByToid(String toid,int pageSize){
    	int pageCount = Integer.parseInt(chatrecordDao.selectCountByToid(toid).getToid());
        return pageCount % pageSize == 0 ? pageCount/pageSize : pageCount/pageSize + 1;
    }
}
